/* -----------------------------
 * 优先加载必要模块
 * --------------------------- */
thin.imports('/public/plug/JQueryWeui/jquery-weui.min.css');
thin.imports('/public/plug/IconFont/style.css');
//thin.imports('/public/plug/SystemTips/SystemTips', 'css');
//thin.imports('/public/plug/weui/css/weui.min', 'css');
thin.imports('/public/home/css/layout.global.css');
thin.imports('/public/home/css/global.css');

thin.imports('/public/plug/JQueryWeui/jquery.min.js', function() {
	thin.imports('/public/plug/JQueryWeui/jquery-weui.min.js');

	(typeof jqcallback == 'function') && jqcallback();
	
	$('.warp').on('click', '[layout-mark=btn-step]', function(e) {
		var hash = $(this).attr('data-hash');
		checkLocation(hash);
	});
});
//thin.require('/public/modules/zepto.min');
//thin.require('/public/modules/jquery.min');
thin.require('/public/modules/tool');
thin.require('/public/modules/interactive');
thin.require('/public/modules/factory');
//thin.require('/public/plug/SystemTips/SystemTips');

// 路由
function checkLocation(hash) {
	if(hash) {
		window.location.hash = hash;
		return;
	}
	var hash = hash || window.location.hash,
		title;
	if(hash == '') {
		var _id = $('.warp:eq(0)').attr('id');
		hash = _id.split('-')[0];
	}
	hash = hash.replace('#', '');
	var hash_opt = {};
	if(!window.hash_opt) {
		$('.warp').each(function(index) {
			var _id = $(this).attr('id');
			hash_opt[_id] = $(this);
		});
		window.hash_opt = hash_opt;
	} else {
		hash_opt = window.hash_opt;
	}
	var reg = new RegExp(hash, 'gi');
	for(var i in hash_opt) {
		if(reg.test(i)) {
			hash_opt[i].show().siblings('.warp').hide();
			title = hash_opt[i].attr('data-title');
			break;
		}
	}
	if(title) {
		checkLocationTitle(title);
	}
	(typeof checkLocationCallback == 'function') && checkLocationCallback(hash);
}

function checkLocationTitle(title) {
	document.title = title;
	var _iframe = document.getElementById('reloadtitleiframe');
	if(!_iframe) {
		_iframe = document.createElement('iframe');
		_iframe.id = 'reloadtitleiframe';
		_iframe.name = 'reloadtitleiframe';
		_iframe.style.display = 'none';
		_iframe.src = '/favicon.ico';
		document.body.appendChild(_iframe);
	}
	window.frames['reloadtitleiframe'].location.reload();
}

window.onpopstate = function() {
	checkLocation();
};